package com.es;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Date;

import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.RowMapper;

import com.es.config.MyCatDBConfig;

public class MycatTest {
	public static void main(String[] args) {
		//https://blog.csdn.net/u013467442/article/details/56955846
		AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(MyCatDBConfig.class);
		JdbcTemplate indexDBTemplate = ctx.getBean("indexDBTemplate",JdbcTemplate.class);
		String sql =""; //"insert into users (name,createdate) values (?,?)";
		//sql = "insert into item(id,value,createdate) values (?,?,?)";
		sql = "select * from item";
		Object[] params = {4,100,new Date()};
		int row = indexDBTemplate.update(sql,params);
		System.out.println(row);
		indexDBTemplate.query(sql, new RowMapper<Object>(){

			@Override
			public Object mapRow(ResultSet rs, int rowNum) throws SQLException {
				System.out.println(rs.getInt("id"));
				return null;
			}
			
		});
		
	}
}
